package com.angel.utils;

import com.angel.bean.Employee;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class NoUtlis {

    /**
     * 员工工号生成算法
     *
     * @param employee 员工基本信息:必须要有分店编号，性别、岗位编号
     * @return 生成的员工工号
     */
    public static String getEpNo(Employee employee) {
        String epNo = "TS";
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMssSSS");
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        epNo = epNo.concat(employee.getBranchesId().toString());
        String tem = sdf.format(d);
        epNo = epNo.concat(tem);
        epNo = epNo.concat(employee.getEmTypeId().toString());
        epNo = epNo.concat(employee.getEmsex().toString());
        epNo = epNo.concat(String.valueOf(new Random().nextInt(10)));
        return epNo;
    }


    /**
     * 生成商品编号，重复率0.5%,需要在数据库匹配
     *
     * @return
     */
    public static String getProductNo() {
        String head = "TS";
        // 生成随机数
        Random rand = new Random();
        String cardNumer = "";
        for (int a = 0; a < 6; a++) {
            // 生成6位数字
            cardNumer += rand.nextInt(10);
        }
        return head + cardNumer;

    }

}
